package cate.game.activity.godequip;

import cate.game.activity.LogDetail;
import cate.game.activity.base.core.ActivityGlobalData;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteField;

import java.util.HashMap;
import java.util.Map;

public class GodEquipGlobalData extends ActivityGlobalData {
    @NoteField(value = "抽取神装日志")
    public Map<Integer, GodEquipDrawLog> logs;

    @Override
    public void initialize() {
        if (logs == null) {
            logs = new HashMap<>();
        }
    }

    @JsonIgnore
    public synchronized void addLog(int activityId, LogDetail logDetail, int maxNum) {
        GodEquipDrawLog log = getLog(activityId);
        log.logs.add(0, logDetail);
        while(log.logs.size() > maxNum){
            log.logs.remove(log.logs.size() - 1);
        }
    }

    public GodEquipDrawLog getLog(int activityId) {
        GodEquipDrawLog log = logs.get(activityId);
        if (log == null) {
            log = new GodEquipDrawLog(activityId);
            log.initialize();
            logs.put(activityId, log);
        }
        return log;
    }

    @Override
    public void clear() {
        logs.clear();
    }
}
